package list.primitive;

/**
 *
 * @author Shimu
 * @date 26-May-2013
 */
public class PrimitiveList {
    
    /** The number of elements in the list. */
    private int elements;
    
    protected PrimitiveList() {
        this.elements = 0;
    }
    
    /**
     * Returns the number of elements in this list.
     * @return 
     */
    public int size() {
        return this.elements;
    }
    
    /**
     * Simply resets the number of elements to 0;
     */
    public void clear() {
        this.elements = 0;
    }
    
    /**
     * Remove all elements including and after the given index.
     * @param index 
     */
    public void trunicate(int index) {
        validateIndex(index);
        this.elements = index;
    }
    
    /**
     * Returns true if this List is empty.
     * @return 
     */
    public boolean isEmpty() {
        return this.elements == 0;
    }
    
    protected void incrementSize() {
        this.elements++;
    }
    
    protected void validateIndex(int index) {
        if (index < 0 || index >= this.size()) {
            throw new IndexOutOfBoundsException(
                    String.format("Number of elements: %d, Index given: %d", this.elements, index));
        }        
    }
    

}
